package engine.resource.inputfile;

import java.io.File;

import engine.game.level.EntityMap;
import engine.game.level.Level;
import engine.game.level.LevelMap;
import engine.resource.ResourceInputFile;
import engine.resource.Resources;

public class LevelConfigFile extends ConfigFile {
	
	private Level level;

	public LevelConfigFile(File file) {
		super(file);
	}
	
	public LevelConfigFile(String path) {
		super(path);
	}

	public void readData() {
		super.readData();
		
		ConfigNode nameNode = nodes.get("NAME");
		String name = nameNode.value("NAME");
		
		ConfigNode levelMapNode = nodes.get("LEVEL_MAP");
		String levelMapPath = ResourceInputFile.getFolderFrom(filePath) + levelMapNode.value("FILE");
		LevelMapConfigFile lvlMapCfg = new LevelMapConfigFile(levelMapPath);
		lvlMapCfg.readData();
		LevelMap lvlMap = lvlMapCfg.levelMap();
		
		ConfigNode entMapNode = nodes.get("ENTITY_MAP");
		String entityMapPath = ResourceInputFile.getFolderFrom(filePath) + entMapNode.value("FILE");
		EntityMapConfigFile entMapCfg = new EntityMapConfigFile(entityMapPath);
		entMapCfg.readData();
		EntityMap entMap = entMapCfg.entityMap();
		
		level = new Level(name, lvlMap, entMap, 16, filePath);
		
		Resources.addLevel(name, level);
	}
	
	public Level level() {
		return level;
	}
	
}
